﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Xml.Serialization;

namespace Urbania.GUI.Elements
{
    [Serializable]
    [XmlRoot("Frame")]
    [XmlInclude(typeof(GUIElement))]
    public class Frame
    {
        private List<GUIElement> elements;
        private LuaVM lua;

        public List<GUIElement> Elements { get { return this.elements; } set { this.elements = value; } }

        public Frame(ref LuaVM lua)
        {
            elements = new List<GUIElement>();
            this.lua = lua;
        }

        public void Update(GameTime gameTime, MouseState mouse)
        {
            foreach (GUIElement e in elements)
                if (e is Button)
                {
                    Button b = (Button)e;
                    b.Update(gameTime, mouse);
                }
                else
                    e.Update(gameTime);    
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (GUIElement e in elements)
            {
                e.Draw(gameTime, spriteBatch);
            }
        }

        public void AddPopUp(PopUp p)
        {
            elements.Add(p);
        }

        public void AddPopUp(Rectangle bounds)
        {
            elements.Add(new PopUp(bounds, ref lua));
        }

        public void AddPopUp(Rectangle bounds, Color bg)
        {
            elements.Add(new PopUp(bounds, bg, ref lua));
        }

        public void AddButton(Button b)
        {
            elements.Add(b);
        }

        public void AddButton(Vector2 position, int designType, string buttonName, string buttonText, string buttonScript)
        {
            elements.Add(new Button(buttonName, position, buttonText, designType, ref lua, buttonScript));
        }
    }
}
